package com.xbongbong.saas.model.impl;

import com.xbongbong.api.domain.entity.ApiCallbackSetEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.ApiCallbackSetDao;
import com.xbongbong.saas.model.ApiCallbackSetModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 *
 * @author 魏荣杰
 * @date 2019/10/10 21:38
 * @since
 * @version
 */
@Service("apiCallbackSetModel")
public class ApiCallbackSetModelImpl implements ApiCallbackSetModel {

    @Resource
    private ApiCallbackSetDao apiCallbackSetDao;

    @Override
    public Integer insert(ApiCallbackSetEntity entity) throws XbbException {
        Long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        entity.setDel(0);
        return apiCallbackSetDao.insert(entity);
    }

    @Override
    public Integer update(ApiCallbackSetEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return apiCallbackSetDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return apiCallbackSetDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return apiCallbackSetDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    /**
     * 保存apiCallbackSet
     * @author lsj
     * @param entity apiCallBackSet实体
     * @return
     * @throws XbbException
     */
    @Override
    public Integer save(ApiCallbackSetEntity entity) throws XbbException {
        if(entity.getId() == null || Objects.equals(0L, entity.getId())) {
            return insert(entity);
        }
        return update(entity);
    }

    /**
     * 根据corpid获取ApiCallbackSet
     * @author lsj
     * @param corpid 公司id
     * @return ApiCallbackSet
     * @throws XbbException
     */
    @Override
    public ApiCallbackSetEntity getByCorpId(String corpid) {
        return apiCallbackSetDao.getByCorpid(corpid);
    }

    public void insertBatch(List<ApiCallbackSetEntity> entityList) {
        apiCallbackSetDao.insertBatch(entityList);
    }

    public Integer deleteByKey( Integer key,  String corpid){
        return apiCallbackSetDao.deleteByKey(key , corpid);
    }

    public ApiCallbackSetEntity getByKey( Integer key,  String corpid){
        return apiCallbackSetDao.getByKey(key , corpid);
    }
}
